<template>
  <YsDropdown placement="right-start" @on-click="handleClick" trigger="hover"
    :class="!IsSecondLevel ? 'first-icon' : ''">
    <YsDropdownItem>
      <span v-if="!IsSecondLevel">{{parent.name}}&nbsp;
        <YsIcon type="ios-arrow-forward" /></span>
      <div v-else class="menu-icon">
        <span v-if="parent.rsim_url != ''" class="iconStyle" :class="parent.rsim_url"></span>
        <YsIcon v-else type="logo-angular" class="menu-icon" />
      </div>
      <!-- <span v-if="parent.rsim_url != ''" class="iconStyle" :class="parent.rsim_url"></span> -->
      <!-- <span v-else class="menu-icon" :class="parent.rsim_url"></span> -->
      <!-- <YsIcon v-else type="logo-angular" class="menu-icon"/> -->
    </YsDropdownItem>
    <YsDropdownMenu slot="list">
      <template v-for="item in parent.tabs">
        <ReDropdown v-if="item.tabs" :key="`drop_${item.rs_code}`" :IsSecondLevel="false" :parent="item">
        </ReDropdown>
        <YsDropdownItem class="everyItem" v-else :key="`drop_${item.rs_code}`" :name="item.frame" :title="item.name"
          :menuRsCode="item.rs_code">{{item.name}}</YsDropdownItem>
      </template>
    </YsDropdownMenu>
  </YsDropdown>
</template>

<script>
  // import { Recursion } from './recursion.js';
  /**
   * 开发者：齐广广
   */
  export default {
    name: 'ReDropdown',
    props: {
      /**
       * 递归组件的数据
       */
      parent: {
        type: Object,
        default: () => ({})
      },
      showTitle: {
        type: Boolean,
        default: true
      },
      // 是否是展开的二级
      IsSecondLevel: {
        type: Boolean,
        default: false
      }
    },
    computed: {
      titleSpan() {
        return {
          textAlign: this.showTitle ? 'left' : 'center',
          paddingLeft: this.showTitle ? '16px' : ''
        }
      }
    },
    methods: {
      handleClick(name) {

        // if (e.target.getAttribute("menuRsCode")) {
        //   let result = Recursion(e.target.getAttribute("menuRsCode"), this.parent.tabs);
      
        //   // this.$emit('on-select', "result");
        // }
        if (name) {
          // let result = Recursion(name)
          this.$emit('on-select', name);
        }
        // if (!this.showTitle) {
        //   this.$emit('on-select', name)
        // }
      }
    },
  }
</script>